package gmap

import "log"

type Scenic struct {
	ScenicName string
	ScenicId   int64
	Address    string
	City       string
	Bounds     string //景区的围栏
	BoundsNum  int64  //景区的围栏点数
}


func (s *Scenic)getScenic(id int64) error {

	row := db.QueryRow("SELECT scenic_id,scenic_name,scenic_addr,city from sn_scenic where scenic_id=? AND is_spider=0", id)

	return row.Scan(&s.ScenicId, &s.ScenicName, &s.Address, &s.City)
}


//更新景区数据
func (s *Scenic)upScenic() error {
	if (s.BoundsNum > 0) {
		stm, err := db.Prepare("INSERT sn_scenic_geofencing(scenic_id,poi_num,polygon) VALUES(?,?,?)")
		if err != nil {
			log.Fatal(err)
		}
		_, err = stm.Exec(s.ScenicId, s.BoundsNum, s.Bounds)
		if err != nil {
			log.Println("error:插入失败;scenic_id:%d", s.ScenicId)
			//return err
		}
	}
	stm, err := db.Prepare("update sn_scenic set is_spider=1 where scenic_id=?")
	if err != nil {
		log.Fatal(err)
	}

	_, err = stm.Exec(s.ScenicId)
	if err != nil {
		log.Fatal(err)
	}
	return nil
}
